<template>
  <div class="log-main">
    <div class="login-container">
      <el-form
        ref="loginForm"
        :model="loginForm"
        :rules="loginRules"
        class="login-form"
        auto-complete="on"
        label-position="left"
      >
        <div class="title-container">
          <div class="logo">
            <img src="@/assets/logo.png" alt="" />
          </div>
          <h3 class="title">农业数字化平台-运维中心</h3>
          <div class="tit-msg">Enterprise Data Service Solutions</div>
        </div>
        <div class="input_style">
          <el-form-item prop="account">
            <span class="svg-container">
              <!-- <svg-icon icon-class="user" /> -->
              <i class="el-icon-user" style="font-size: 26px;"></i>
            </span>
            <el-input
              ref="account"
              v-model="loginForm.account"
              placeholder="请输入用户名"
              name="account"
              type="text"
              tabindex="1"
              autocomplete="on"
            />
          </el-form-item>

          <el-form-item prop="password">
            <span class="svg-container">
              <i class="el-icon-lock" style="font-size: 26px;"></i>
            </span>
            <el-input
              :key="passwordType"
              ref="password"
              v-model="loginForm.password"
              :type="passwordType"
              placeholder="请输入密码"
              name="password"
              tabindex="2"
              autocomplete="on"
              @keyup.enter.native="handleLogin"
            />
            <span class="show-pwd" @click="showPwd">
              <svg-icon
                style="color:rgba(0, 203, 134, 1)"
                :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
              />
            </span>
          </el-form-item>
          <div class="new-msg">
            <div class="rember-msg">
              <el-checkbox v-model="remberMsg" label="记住密码" />
            </div>
            <div class="forget-msg">
              忘记密码
            </div>
          </div>
          <el-button
            :loading="loading"
            type="primary"
            style="width: 100%; margin-bottom: 10px;background-color:rgba(127, 211, 84);height: 40px;font-size:18px;"
            @click.native.prevent="handleLogin"
          >
            登录
          </el-button>
        </div>
        <!-- <div class="reg-user" @click="toreguser()">注册账户</div> -->
      </el-form>
    </div>
    <div class="copyright">
      版权所有：中科台达（浙江）信息技术有限公司｜
      Copyright © 2019-2025 casdelta.com All Right Reserved
      <a
        href="https://beian.miit.gov.cn"
        target="view_window"
      >
        备案号：浙ICP备19034790号-5</a>
    </div>
    <!-- 特殊 -->
    <!-- <div class="copyright">
      版权所有：COPYRIGHT © 渔雅科技（上海）有限公司
      <br />
      <a href="https://beian.miit.gov.cn" target="view_window">
        ICP备案号：沪ICP备20003371号-1</a>
    </div> -->
    <div class="future">
      <img src="@/assets/login/future.png" class="futureback" alt="" />
      <div class="futurecenter">Future</div>
    </div>

    <div class="smart">
      <img src="@/assets/login/smart.png" class="smartback" alt="" />
      <div class="smartcenter">Smart</div>
    </div>

    <div class="data">
      <img src="@/assets/login/data.png" class="databack" alt="" />
      <div class="datacenter">数字化</div>
    </div>

    <div class="weather">
      <img
        src="@/assets/login/weatherbor.png"
        class="weatherback"
        alt=""
      />
      <img
        src="@/assets/login/weather.png"
        class="weathercenter"
        alt=""
      />
    </div>
    <div class="tv">
      <img src="@/assets/login/tvbor.png" class="tvback" alt="" />
      <img src="@/assets/login/tv.png" class="tvcenter" alt="" />
    </div>

    <div class="green">
      <img src="@/assets/login/green.png" class="greenback" alt="" />
      <div class="greencenter">Green</div>
    </div>

    <div class="iot">
      <img src="@/assets/login/iot.png" class="iotback" alt="" />
      <div class="iotcenter">物联网</div>
    </div>
    <div class="qixiang">
      <img src="@/assets/login/qi.png" class="qiback" alt="" />
      <div class="qicenter">气象</div>
    </div>

    <div class="oc">
      <img src="@/assets/login/ocbor.png" class="ocback" alt="" />
      <img src="@/assets/login/oc.png" class="occenter" alt="" />
    </div>

    <div class="fisheries">
      <img
        src="@/assets/login/fisheries.png"
        class="fisheriesback"
        alt=""
      />
      <div class="fisheriescenter">Fisheries</div>
    </div>
  </div>
</template>

<script>
import { validUsername } from "@/utils/validate";
import userService from "@/api/user/index";
export default {
  name: "Login",
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!validUsername(value)) {
        callback(new Error("请输入用户名"));
      } else {
        callback();
      }
    };
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error("密码不得小于六位"));
      } else {
        callback();
      }
    };
    return {
      remberMsg: false,
      loginForm: {
        // account: "jg",
        // password: "123456"
        account: "",
        password: ""
      },
      loginRules: {
        account: [
          { required: true, trigger: "blur", validator: validateUsername }
        ],
        password: [
          { required: true, trigger: "blur", validator: validatePassword }
        ]
      },
      loading: false,
      passwordType: "password",
      redirect: undefined
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  mounted() {
    this.getquery();
  },
  created() {
    if (this.$store.state.permission.addRoutes.length > 0) { // 判断是否已经刷新
      location.reload()
    }
  },
  methods: {
    getquery() {
      let tr = this.$route.query;
      if (tr.account) {
        console.log(tr);
        this.loginForm.account = decodeURIComponent(tr.account);
        this.loginForm.password = tr.password;
        this.handleLogin();
      }
    },
    // 注册用户
    toreguser() {
      this.$router.push({ path: "/register-user" })
    },
    showPwd() {
      if (this.passwordType === "password") {
        this.passwordType = "";
      } else {
        this.passwordType = "password";
      }
      this.$nextTick(() => {
        this.$refs.password.focus();
      });
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          this.$store
            .dispatch("user/login", this.loginForm)
            .then(() => {
              this.loading = false;
              // this.$router.push({ path: this.redirect || "/" });
              // this.$router.push({ name: "selectBaseManage" })
              this.$router.push({ name: "selectBaseManage" })
            })
            .catch(async (err) => {
              // console.log(err)
              this.$message.warning(err || '用户账号/密码错误(或已被加入黑名单),请确认后重试或联系管理员')
              this.loading = false;
            });
        } else {
          console.log("表单提交错误!!");
          return false;
        }
      });
    },
    // 主要用于登录完判断进入哪个页面--暂时没什么用
    gotoview() {
      // 获取顶级组织结构id,
      userService.organizationTop().then(
        res => {
          let companylist = res.data
          alert(companylist.length)
          if (companylist.length > 1) {
            this.$router.push({ path: "/select-farm", query: { id: companylist[0]["companyId"] } });
          } else if (companylist.length === 1) {
            this.$router.push({ path: "/choose-company", query: { id: companylist[0]["companyId"] } });
          }
        }
      )

      this.loading = false;
    }
  }
};
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #283443;
$light_gray: #fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* 登录主体样式 */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;
    input {
      background: transparent;
      border: 0px;
      appearance: none;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;
      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}

</style>

<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;
.log-main{
  width: 100%;
  height: 100%;
  background: linear-gradient(150.62deg, rgba(0, 203, 134, 1) 0%, rgba(31, 124, 135, 1) 100%, rgba(26, 135, 133, 1) 100%);
  // overflow:auto;
  overflow: hidden;
  position: relative;
  // overflow-y: hidden;
  // overflow-x: hidden;
  // -ms-overflow-style: auto;
}
// .log-main::-webkit-scrollbar { width: 0 !important }
.login-container {
  min-height: 100%;
  width: 100%;
  background-size: 100% 100% !important;
  background-attachment: fixed !important;
  background: url("~@/assets/login/back.png") center center no-repeat;
  // overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  .login-form {
    position: relative;
    width: 565px;
    max-width: 100%;
    top: -20px;
    margin: auto;
    // overflow: hidden;
    background-color: rgba(0, 81, 81, 0.8);
    z-index: 99;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    margin-top: 28px;
    position: relative;
    top: 18px;
    .logo {
      text-align: center;
      img {
        width: 120px;
        height: auto;
      }
    }
    .title {
      font-size: 26px;
      color: #fff;
      margin: 20px auto 2px auto;
      text-align: center;
      font-weight: bold;
    }
    .tit-msg{
      color: rgba(255, 255, 255, 0.56);
      text-align: center;
      margin-bottom: 35px;
    }
  }
  .input_style {
    padding: 20px;
    box-sizing: border-box;
    .svg-container{
      color: rgba(127, 211, 84);
    }
    ::v-deep .el-input input {
      caret-color: #7fd354;
      margin-left: 20px;
      outline:none !important;
      border:none !important;
      padding: 0 !important;
      color: $bg;
    }
    // 自动填充样式input,真恶心
    ::v-deep .el-input{
        .el-input__inner:-webkit-autofill, .el-input__inner:-webkit-autofill:hover, .el-input__inner:-webkit-autofill:active, .el-input__inner:-webkit-autofill{
            margin-left: 20px;
            outline:none !important;
            border:none !important;
            padding: 0 !important;
            -webkit-box-shadow: 0 0 0px 1000px rgb(246, 246, 246) inset !important;
            box-shadow: 0 0 0px 1000px rgb(246, 246, 246) inset !important;
            -webkit-text-fill-color: #2d3a4b !important;
        }
    }
    ::v-deep .el-form-item__content {
      border: 1px solid rgba(217, 217, 217, 1);
      border-radius: 2px;
      background-color: #fff;
    }
    // 记住密码与忘记密码
    .new-msg{
      display: flex;
      margin-bottom: 20px;
      width: 525px ;
      justify-content: space-between;
      .rember-msg{
        width: 80px;
        height: 22px;
        color: rgba(255, 255, 255, 0.65);
        font-size: 14px;
        line-height: 22px;
        .el-checkbox{
          color: rgba(255, 255, 255, 0.65);
          font-size: 14px;
        }
        ::v-deep .el-checkbox__input.is-checked+.el-checkbox__label {
            color: #7fd354;
        }
        ::v-deep .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
            background-color: #7fd354;
            border-color: #7fd354;
        }
      }
      .forget-msg{
        margin-right: 10px;
        width: 56px;
        height: 22px;
        color: #7fd354;
        font-size: 14px;
        line-height: 22px;
        cursor: pointer;
      }
    }
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
  .reg-user{
    width: 565px;
    text-align: center;
    height: 22px;
    color: rgba(127, 211, 84, 1);
    font-size: 14px;
    line-height: 22px;
    cursor: pointer;
    margin-bottom: 20px;
  }
}
</style>
<style lang="scss" scoped>
.copyright {
  width: 100%;
  position: absolute;
  bottom: 0px;
  text-align: center;
  color: white;
  line-height: 2;
  font-size: 10px;
  margin-bottom: 0;
  background-color: rgba(32, 3, 4, 0.35);
}

.future {
  position: absolute;
  top: 23%;
  left: 27%;
  display: flex;
  justify-content: center;
  align-items: center;
  .futureback {
    width: 270px;
    position: absolute;
    animation: upmove 15s linear infinite;
    -moz-animation: upmove 15s linear infinite; /* Firefox */
    -webkit-animation: upmove 15s linear infinite; /* Safari and Chrome */
    -o-animation: upmove 15s linear infinite; /* Opera */
  }
  .futurecenter {
    font-size:42px;
    color: #fff;
  }
}
.smart {
  position: absolute;
  top: 69%;
  left: 20%;
  display: flex;
  justify-content: center;
  align-items: center;
  .smartback {
    width: 300px;
    position: absolute;
    animation: upmove 8s linear infinite;
    -moz-animation: upmove 8s linear infinite; /* Firefox */
    -webkit-animation: upmove 8s linear infinite; /* Safari and Chrome */
    -o-animation: upmove 8s linear infinite; /* Opera */
  }
  .smartcenter {
    font-size: 35px;
    color: #fff;
  }
}

.data {
  position: absolute;
  top: 72%;
  left: 75%;
  display: flex;
  justify-content: center;
  align-items: center;
  .databack {
    width: 18vw;
    position: absolute;
    animation: upmove 10s linear infinite;
    -moz-animation: upmove 10s linear infinite; /* Firefox */
    -webkit-animation: upmove 10s linear infinite; /* Safari and Chrome */
    -o-animation: upmove 10s linear infinite; /* Opera */
  }
  .datacenter {
    font-size: 35px;
    color: #fff;
  }
}
.weather {
  position: absolute;
  top: 45%;
  left: 82.1%;
  display: flex;
  justify-content: center;
  align-items: center;
  .weatherback {
    width: 210px;
    position: absolute;
    animation: upmove 8s linear infinite;
    -moz-animation: upmove 8s linear infinite; /* Firefox */
    -webkit-animation: upmove 8s linear infinite; /* Safari and Chrome */
    -o-animation: upmove 8s linear infinite; /* Opera */
  }
  .weathercenter {
    color: #fff;
  }
}
.tv {
  position: absolute;
  top: 82%;
  left: 38%;
  display: flex;
  justify-content: center;
  align-items: center;
  .tvback {
    width: 160px;
    position: absolute;
    animation: mymove 5s ease-in-out infinite;
    -moz-animation: mymove 5s ease-in-out infinite; /* Firefox */
    -webkit-animation: mymove 5s ease-in-out infinite; /* Safari and Chrome */
    -o-animation: mymove 5s ease-in-out infinite; /* Opera */
  }
}

.green {
  position: absolute;
  top: 23%;
  left: 88%;
  display: flex;
  justify-content: center;
  align-items: center;
  .greenback {
    width: 12vw;
    position: absolute;
    animation: upmove 8s linear infinite;
    -moz-animation: upmove 8s linear infinite; /* Firefox */
    -webkit-animation: upmove 8s linear infinite; /* Safari and Chrome */
    -o-animation: upmove 8s linear infinite; /* Opera */
  }
  .greencenter {
    font-size: 25px;
    color: #fff;
  }
}

.iot {
  position: absolute;
  top: 16%;
  left: 66%;
  display: flex;
  justify-content: center;
  align-items: center;
  .iotback {
    width:185px;
    position: absolute;
    animation: upmove 15s linear infinite;
    -moz-animation: upmove 15s linear infinite; /* Firefox */
    -webkit-animation: upmove 15s linear infinite; /* Safari and Chrome */
    -o-animation: upmove 15s linear infinite; /* Opera */
  }
  .iotcenter {
    font-size: 30px;
    color: #fff;
  }
}
.qixiang {
  position: absolute;
  top: 79%;
  left: 12%;
  display: flex;
  justify-content: center;
  align-items: center;
  .qiback {
    width: 110px;
    position: absolute;
    animation: upmove 15s linear infinite;
    -moz-animation: upmove 15s linear infinite; /* Firefox */
    -webkit-animation: upmove 15s linear infinite; /* Safari and Chrome */
    -o-animation: upmove 15s linear infinite; /* Opera */
  }
  .qicenter {
    font-size: 20px;
    color: #fff;
  }
}

.oc {
  position: absolute;
  top: 18%;
  left: 10%;
  display: flex;
  justify-content: center;
  align-items: center;
  .ocback {
    width: 70px;
    position: absolute;
    animation: mymove 5s ease-in-out infinite;
    -moz-animation: mymove 5s ease-in-out infinite; /* Firefox */
    -webkit-animation: mymove 5s ease-in-out infinite; /* Safari and Chrome */
    -o-animation: mymove 5s ease-in-out infinite; /* Opera */
  }
}

.fisheries {
  position: absolute;
  top: 40%;
  left: 9%;
  display: flex;
  justify-content: center;
  align-items: center;
  .fisheriesback {
    width: 180px;
    position: absolute;
    animation: mymove 5s ease-in-out infinite;
    -moz-animation: mymove 5s ease-in-out infinite; /* Firefox */
    -webkit-animation: mymove 5s ease-in-out infinite; /* Safari and Chrome */
    -o-animation: mymove 5s ease-in-out infinite; /* Opera */
  }
  .fisheriescenter {
    font-size: 24px;
    color: #fff;
  }
}
@keyframes upmove {
  0% {
    transform: rotateZ(0deg);
    -webkit-transform: rotateZ(0deg);
    -moz-transform: rotateZ(0deg);
    -o-transform: rotateZ(0deg);
    -ms-transform: rotateZ(0deg);
  }
  100% {
    transform: rotateZ(360deg);
    -webkit-transform: rotateZ(360deg);
    -moz-transform: rotateZ(360deg);
    -o-transform: rotateZ(360deg);
    -ms-transform: rotateZ(360deg);
  }
}
@keyframes mymove {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    //  background-position: 100% 0%;
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    //  background-position: 100% 0%;
    transform: scale(1);
    opacity: 1;
  }
}
</style>
